<?php


// nicht mehr aktuell!!!!!!!!!!!!!!!!!!!!!!


class rssFeedItem {
    
    public $title;
    public $text;
    
    
    
}



class rss_data
    {
    public $data = array();
    
    public $feedTitle = "";
    public $feedText = "";
    public $feedImage = "";
    
    

    function __construct() { 
        
       /* $data = $this->getRssFeed($rssUrl);
        return $data;*/
    
    
    }

    function getRssFeed($rssUrl)
        {
        global $rootDir;
        global $webDir;
        include_once($rootDir . $webDir . '/api/simplepie/simplepie.inc');
        include_once($rootDir . $webDir . '/api/simplepie/idn/idna_convert.class.php');

        $inhaltNeu="";

        //$rssUrl = "http://www.tagesanzeiger.ch/rss_ticker.html";
        //$rssUrl   ="[php_property:url]";
        $rssUrl   =str_replace("&amp;", "&", $rssUrl);
        //echo $rssUrl;

        //http://gdata.youtube.com/feeds/base/videos?q=google&client=ytapi-youtube-search&alt=rss&v=2

        $feed     =new SimplePie();

        //  $feed->set_output_encoding('ISO-8859-1');

        //set_output_encoding ( [string $encoding = 'UTF-8'] )
        $feed->enable_cache(false);
        $feed->set_feed_url($rssUrl);
        $feed->init();
        $feed->handle_content_type();
        //$item = $feed->get_item(0); 

        
        
        $this->feedTitle = html::decodeHtml($feed->get_title());
        $this->feedText = html::decodeHtml($feed->get_description()); 
        $this->feedImage = trim($feed->get_image_url());
       
        
        
        
        $feedArray=array();

        foreach ($feed->get_items()as $item)
            {
            //echo "Title" .$item->get_title();

            /*$text = $item->get_title();
            if(mb_detect_encoding($text, 'UTF-8, ISO-8859-1') === 'UTF-8'){

                    $text = utf8_decode($text);  
                    } */

            $url       = $item->get_link();
            $title     =html::decodeHtml($item->get_title());
            $text      =html::decodeHtml($item->get_content());


            /*        if ($enclosure = $item->get_enclosure())
            {
                echo $enclosure->embed();
            } */

            $mp3       ="";
            $image     ="";

            $enclosures=$item->get_enclosures();

            if (sizeof($enclosures) > 0)
                {
                foreach ($enclosures as $enclosure)
                    {
                    
                        echo $enclosure->get_type();
                        
                        if ($enclosure->get_type() == "image/jpeg") 
                        $image=$enclosure->get_link();
                   

                    if ($enclosure->get_type() == "audio/mpeg")
                        $mp3=$enclosure->get_link();
                    
                    
                    //video/x-m4v
                    
                    
                    }
                }

            $value = array();
            $value['title']=$title;
            $value['text'] =$text;
            $value['url']  =$url;

            $value['image']=$image;
            $value['mp3']  =$mp3;

            $tmp = new rssFeedItem();
            $tmp->title = $title;
            $tmp->text = $text;
            $feedArray[] = $tmp;
            
            
            
            //$feedArray[] = $value;
            //$this->data[]  =$value;


            //echo $title."<br>".$text."<br><br>";

            //echo html::convertHTML($item->get_title());
            }
            
            
        return $feedArray;
            
            
            
        }
    }
?>